package org.knot.mockejb3.createors;


public class DefaultServiceImpl{

    public static Class getServiceImplClass(Class interfaceClass) throws ClassNotFoundException {
        Package p = interfaceClass.getPackage();
        String packagename =  p.getName();
        try {  
            if(packagename.endsWith(".service"))
            {
                
                StringBuffer bufferClassname = new StringBuffer(packagename);
                bufferClassname.append(".impl.").append(interfaceClass.getSimpleName()).append("Impl");
                    return  interfaceClass.getClassLoader().loadClass(
                            bufferClassname.toString());
            }
            else
            {
                StringBuffer bufferClassname = new StringBuffer(packagename.substring(0, packagename.lastIndexOf(".")));
                bufferClassname.append(".impl").append(packagename.substring(packagename.lastIndexOf("."))).append(".").append(interfaceClass.getSimpleName()).append("Impl");
                return  interfaceClass.getClassLoader().loadClass(
                        bufferClassname.toString());
            }
        } catch (ClassNotFoundException e) {
            System.err.println("实现类不符合约定的规则；");
            e.printStackTrace();
            throw e;
//            System.exit(-1);
        }
    }

    
}
